<template>
  <div class="login-form">
    <div class="form-container">
      <h2>登录</h2>
      <form @submit.prevent="handleSubmit">
        <div class="form-group">
          <input 
            type="text" 
            v-model="username" 
            placeholder="用户名"
            required
          >
        </div>
        <div class="form-group">
          <input 
            type="password" 
            v-model="password" 
            placeholder="密码"
            required
          >
        </div>
        <button type="submit">登录</button>
      </form>
    </div>
  </div>
</template>

<script>
import auth from '@/api/auth'

export default {
  name: 'LoginForm',
  data() {
    return {
      username: '',
      password: '',
      loading: false
    }
  },
  methods: {
    async handleSubmit() {
      try {
        this.loading = true
        const response = await auth.login({
          username: this.username,
          password: this.password
        })
        // 存储 token
        localStorage.setItem('token', response.token)
        // 登录成功后的处理
        this.$router.push('/dashboard') // 假设登录后跳转到仪表板
      } catch (error) {
        console.error('登录失败：', error)
        // 这里可以添加错误提示
      } finally {
        this.loading = false
      }
    }
  }
}
</script>

<style scoped>
.login-form {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  width: 100%;
  margin: 0;
  padding: 0;
  background: linear-gradient(
    135deg, 
    #050505 0%,
    #0f0f0f 50%,
    #030303 100%
  );
  animation: gradientBG 15s ease infinite;
  background-size: 400% 400%;
}

@keyframes gradientBG {
  0% {
    background-position: 0% 50%;
  }
  50% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0% 50%;
  }
}

.form-container {
  background: rgba(18, 18, 18, 0.8);
  backdrop-filter: blur(10px);
  padding: 3rem;
  border-radius: 12px;
  width: 400px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

h2 {
  color: #fff;
  text-align: center;
  font-size: 1.8rem;
  margin-bottom: 3rem;
}

.form-group {
  margin-bottom: 1.5rem;
}

input {
  width: 100%;
  padding: 1rem;
  border: 1px solid #2a2a2a;
  border-radius: 4px;
  background: #252525;
  color: #e0e0e0;
  box-sizing: border-box;
  font-size: 1.1rem;
}

input:focus {
  outline: none;
  border-color: #404040;
  box-shadow: 0 0 5px rgba(64, 64, 64, 0.5);
}

button {
  width: 100%;
  padding: 1rem;
  background: #2a2a2a;
  color: #fff;
  border: 1px solid #404040;
  border-radius: 4px;
  cursor: pointer;
  font-size: 1.2rem;
  transition: all 0.3s ease;
  margin-top: 1rem;
}

button:hover {
  background: #404040;
  border-color: #505050;
}
</style>